package com.ktwlsoft.archivemanage.controller.problemReply;

import com.ktwlsoft.archivemanage.domain.business.businessService.problemReply.ProblemReplyService;
import com.ktwlsoft.archivemanage.domain.dao.entity.problemReply.ProblemReply;
import com.ktwlsoft.archivemanage.service.security.UserAuthenticate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;

import javax.validation.Valid;

/**
 * problem_reply-一问一答控制层
 *
 * @author 
 * @date 2023/09/19
 */
@Api(value = "一问一答", description = "一问一答")
@RestController
@RequestMapping(value = "problemReply")
@RequiredArgsConstructor
public class ProblemReplyController {

    private final ProblemReplyService service;

    @ApiOperation(value = "一问一答列表",tags = {"1.3"})
    @ResponseBody
    @GetMapping("findPage")
    @UserAuthenticate(actionCode = "PROBLEM_REPLY_FIND_PAGE", skip = true)
    public ResponseEntity<?> findPage(@RequestParam(defaultValue = "1") int pn,
                                      @RequestParam(defaultValue = "30") int pageSize,
                                      @ApiParam(name = "keyWords", value = "关键字") @RequestParam(defaultValue = "") String keyWords,
                                      @ApiParam(name = "state", value = "状态:-1未发布,0.待回复,1.已发布") @RequestParam(defaultValue = "") Integer state){
        return ResponseEntity.ok(service.findPage(pn,pageSize,keyWords,state));
    }

    @ApiOperation(value = "一问一答发布列表",tags = {"1.3"})
    @ResponseBody
    @GetMapping("releaseFindPage")
    @UserAuthenticate(actionCode = "PROBLEM_REPLY_RELEASE_FIND_PAGE", skip = true)
    public ResponseEntity<?> releaseFindPage(@RequestParam(defaultValue = "1") int pn,
                                      @RequestParam(defaultValue = "30") int pageSize){
        return ResponseEntity.ok(service.releaseFindPage(pn,pageSize));
    }

    @ApiOperation(value = "我的提问",tags = {"1.3"})
    @ResponseBody
    @GetMapping("myProblem")
    @UserAuthenticate(actionCode = "PROBLEM_REPLY_MY_PROBLEM", skip = true)
    public ResponseEntity<?> myProblem(@RequestParam(defaultValue = "1") int pn,
                                      @RequestParam(defaultValue = "30") int pageSize){
        return ResponseEntity.ok(service.myProblem(pn,pageSize));
    }

    @ApiOperation(value = "提问",tags = {"1.3"})
    @ResponseBody
    @PostMapping("problem")
    @UserAuthenticate(actionCode = "PROBLEM_REPLY_PROBLEM", skip = true)
    public ResponseEntity<?> problem(@RequestBody @Valid ProblemReply problemReply){
        return ResponseEntity.ok(service.problem(problemReply));
    }

    @ApiOperation(value = "修改",tags = {"1.3"})
    @ResponseBody
    @PostMapping("update")
    @UserAuthenticate(actionCode = "PROBLEM_REPLY_PROBLEM", skip = true)
    public ResponseEntity<?> update(@RequestBody @Valid ProblemReply problemReply){
        return ResponseEntity.ok(service.update(problemReply));
    }
}
